package com.godpaper.as9.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.godpaper.as9.bussiness.delegates.MessageDelegate;
	import com.godpaper.as9.events.GetMessageListEvent;
	import com.godpaper.as9.model.MessageModelLocator;
	
	import mx.rpc.IResponder;

	public class GetMessageListCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:MessageDelegate;
		private var messageModel:MessageModelLocator = MessageModelLocator.getInstance();
		private var getMessageListEvent:GetMessageListEvent;
		public function GetMessageListCommand()
		{
			super();
			delegate = new MessageDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			getMessageListEvent = GetMessageListEvent(event);
			delegate.read(getMessageListEvent.pno);
		}
		
		override public function result(data:Object):void
		{
			if(data.result)
			{
				messageModel.messageList.removeAll();
				messageModel.messageList.source = data.result;
			}
		}
		
		
	}
}